/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) radix(10) lradix(10) 
// Source File Name:   CasMappingAuthenticationEntryPoint.java

package com.eorchis.components.security.casclient.entrypoint;

import com.eorchis.components.security.casclient.common.MappingStrategy;
import com.eorchis.utils.OrchidHttp;
import java.io.IOException;
import java.net.URLEncoder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jasig.cas.client.util.CommonUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.cas.ServiceProperties;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.util.Assert;

public class CasMappingAuthenticationEntryPoint implements AuthenticationEntryPoint, InitializingBean {

	public CasMappingAuthenticationEntryPoint() {
		encodeServiceUrlWithSessionId = true;
	}

	public void afterPropertiesSet() throws Exception {
		Assert.notNull(serviceProperties, "serviceProperties must be specified");
		Assert.notNull(serviceProperties.getService(), "serviceProperties.getService() cannot be null.");
	}

	public void commence(HttpServletRequest servletRequest, HttpServletResponse response, AuthenticationException authenticationException) throws IOException, ServletException {
		String urlEncodedService = createServiceUrl(servletRequest, response);
		String redirectUrl = createRedirectUrl(urlEncodedService, servletRequest);
		StringBuffer callbackUrl = new StringBuffer(servletRequest.getRequestURL().toString());
		if (servletRequest.getQueryString() != null && !"".equals(servletRequest.getQueryString()))
			callbackUrl.append((new StringBuilder()).append("?").append(servletRequest.getQueryString()).toString());
		response.sendRedirect((new StringBuilder()).append(redirectUrl).append(URLEncoder.encode("?call_back=")).append(OrchidHttp.getOrchidHttpUrl(callbackUrl.toString())).toString());
	}

	protected String createServiceUrl(HttpServletRequest request, HttpServletResponse response) throws ServletException {
		String callBackServer = (new StringBuilder()).append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort()).append(request.getContextPath()).append("/").append("j_spring_cas_security_check").toString();
		return callBackServer;
	}

	protected String createRedirectUrl(String serviceUrl, HttpServletRequest request) throws ServletException {
		String casServerLoginUrl = mappingStrategy.getCasServerUrlPrefixsRelateByServerNamesBinded((new StringBuilder()).append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort()).append(request.getContextPath()).toString());
		
		if (casServerLoginUrl == null || "".equals(casServerLoginUrl)){
			casServerLoginUrl=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
//			throw new ServletException((new StringBuilder()).append("Getting casServerLoginUrl exception, Can't find corresponding domain name ,key:").append(request.getServerName()).toString());
		}
//		else
			return CommonUtils.constructRedirectUrl(casServerLoginUrl, serviceProperties.getServiceParameter(), serviceUrl, serviceProperties.isSendRenew(), false);
	}

	/**
	 * @deprecated Method setEncodeServiceUrlWithSessionId is deprecated
	 */

	public final void setEncodeServiceUrlWithSessionId(boolean encodeServiceUrlWithSessionId) {
		this.encodeServiceUrlWithSessionId = encodeServiceUrlWithSessionId;
	}

	/**
	 * @deprecated Method getEncodeServiceUrlWithSessionId is deprecated
	 */

	protected boolean getEncodeServiceUrlWithSessionId() {
		return encodeServiceUrlWithSessionId;
	}

	public final ServiceProperties getServiceProperties() {
		return serviceProperties;
	}

	public final void setServiceProperties(ServiceProperties serviceProperties) {
		this.serviceProperties = serviceProperties;
	}

	public MappingStrategy getMappingStrategy() {
		return mappingStrategy;
	}

	public void setMappingStrategy(MappingStrategy mappingStrategy) {
		this.mappingStrategy = mappingStrategy;
	}

	public static final String CALL_BACK_URL = "call_back";
	public static final String CALL_BACK_SPLIT = "#cbsplit#";
	private MappingStrategy mappingStrategy;
	public static final String CALL_BACK_ENTRANCE = "j_spring_cas_security_check";
	private ServiceProperties serviceProperties;
	/**
	 * @deprecated Field encodeServiceUrlWithSessionId is deprecated
	 */
	private boolean encodeServiceUrlWithSessionId;
}


/*
	DECOMPILATION REPORT

	Decompiled from: D:\.m2\com\eorchis\orchid-components\1.5.3\orchid-components-1.5.3.jar
	Total time: 161 ms
	Jad reported messages/errors:
	Exit status: 0
	Caught exceptions:
*/